import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QPalette
from PyQt5.QtCore import Qt
from ui_textEditer import Ui_TextEditer

class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_TextEditer()
        self.ui.setupUi(self)
        
        self.ui.radioBlack.clicked.connect(self.do_setTextcolor)
        self.ui.radioRed.clicked.connect(self.do_setTextcolor)
        self.ui.radioBlue.clicked.connect(self.do_setTextcolor)
        
#===由connectSlotsByName()自动关联的槽函数======================================
    def on_underline_toggled(self, checked):
        font = self.ui.textEdit.font()
        font.setUnderline(checked)
        self.ui.textEdit.setFont(font)

    def on_italic_toggled(self, checked):
        font = self.ui.textEdit.font()
        font.setItalic(checked)
        self.ui.textEdit.setFont(font)

    def on_bold_toggled(self, checked):
        font = self.ui.textEdit.font()
        font.setBold(checked)
        self.ui.textEdit.setFont(font)

#===自定义的槽函数==============================================================
    def do_setTextcolor(self):
        pale = self.ui.textEdit.palette()
        pale.setColor(QPalette.Text, Qt.red)
        if (self.ui.radioBlack.isChecked()):
            pale.setColor(QPalette.Text, Qt.black)
        elif (self.ui.radioRed.isChecked()):
            pale.setColor(QPalette.Text, Qt.red)
        elif (self.ui.radioBlue.isChecked()):
            pale.setColor(QPalette.Text, Qt.blue)
        self.ui.textEdit.setPalette(pale)
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    form = QmyWidget()
    form.show()
    sys.exit(app.exec_())
